//
//  AppDelegate.m
//  XiangMuB
//
//  Created by 999999999999 on 16/8/12.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "AppDelegate.h"
#import "RootTabBarViewController.h"
#import <AVOSCloud/AVOSCloud.h>
#import "NSObject+alertView.h"//alert
#import "SettingViewController.h"

#import "ContentModel.h"
#import "ObjectIdArrayModel.h"

#import "DataManager.h"
@import AVFoundation;


#import <UMSocial.h>
#import <UMSocialSinaSSOHandler.h>

#import "DataBaseHandle.h"

#import <iflyMSC/IFlySpeechUtility.h>//科大讯飞




@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


    //科大讯飞传入appid
    NSString *strID = [NSString stringWithFormat:@"appid = %@",@"	57bba5f8"];
    [IFlySpeechUtility  createUtility:strID];

    

    

    //获取夜间模式状态
    [ThemeManage shareThemeManage].isNight = [[NSUserDefaults standardUserDefaults]boolForKey:@"night"];
    
    [AVOSCloud setApplicationId:@"yAMt5gCDPeDvl81Gknlo0Sjl-gzGzoHsz" clientKey:@"Dg55DfWBWgiXuQHrVQtuzeGv"];
    
    
    //统计应用启动情况
    [AVAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
    
    
    [ContentModel registerSubclass];
    [ObjectIdArrayModel registerSubclass];
    
    
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    [[DataManager shareManager] getSIDArrayWithURLString:@"http://c.m.163.com/nc/video/home/0-10.html"
                                                 success:^(NSArray *sidArray, NSArray *videoArray) {
                                                     self.sidArray =[NSArray arrayWithArray:sidArray];
                                                     self.videoArray = [NSArray arrayWithArray:videoArray];
                                                 }
                                                  failed:^(NSError *error) {
                                                      
                                                  }];
    
    NSError *setCategoryErr = nil;
    NSError *activationErr  = nil;
    [[AVAudioSession sharedInstance]
     setCategory: AVAudioSessionCategoryPlayback
     error: &setCategoryErr];
    [[AVAudioSession sharedInstance]
     setActive: YES
     error: &activationErr];
    
    
    //    创建UIwindow对象
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    //    设置window 的根视图控制器
    RootTabBarViewController *view = [[RootTabBarViewController alloc] init];

 
    self.window.rootViewController = view;
    
    
    //    数据库打开及建表
    [[DataBaseHandle shareDataBaseHandle]openDatabase];
    [[DataBaseHandle shareDataBaseHandle]CreateTable];
    
    [UMSocialData setAppKey:@"57b3dcf367e58e7ccf002006"];
    
    [UMSocialSinaSSOHandler openNewSinaSSOWithAppKey:@"1851451300" secret:@"f22e2d77b61a3fba4787d2573354cd0d" RedirectURL:@"http://sns.whalecloud.com/sina2/callback"];
    
    
    return YES;
}


+(AppDelegate *)shareAppDelegate{
    return (AppDelegate *) [UIApplication sharedApplication].delegate;

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    BOOL result = [UMSocialSnsService handleOpenURL:url];
    if (result == FALSE) {
        //调用其他SDK，例如支付宝SDK等
    }
    return result;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    
    
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
